package net.runsystem.magiccloud;

import net.runsystem.magiccloud.adapter.OnFragmentClickListener;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;

public class A02_Login extends Fragment implements OnClickListener {
	public static final int A02_FRAGMENT_CODE = 102;
	OnFragmentClickListener onFragmentClickListener;

	View root;

	ImageView btlogin;
	ImageView btpassword;
	ImageView btcreate;

	EditText textID;
	EditText textpass;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		Log.e("A02_Login", "View onCreateView");
		// TODO Auto-generated method stub
		// return super.onCreateView(inflater, container, savedInstanceState);
		root = inflater.inflate(R.layout.a02_layout, container, false);

		btpassword = (ImageView) root.findViewById(R.id.a02_bt_password);
		btcreate = (ImageView) root.findViewById(R.id.a02_bt_create);
		btlogin = (ImageView) root.findViewById(R.id.a02_bt_login);
		textID = (EditText) root.findViewById(R.id.a02_text_ID);
		textpass = (EditText) root.findViewById(R.id.a02_text_pass);

		btlogin.setOnClickListener(this);
		btcreate.setOnClickListener(this);
		btpassword.setOnClickListener(this);

		return root;
	}

	@Override
	public void onClick(View arg0) {

		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.a02_bt_login:
			// insert code
			break;
		case R.id.a02_bt_create:
			// next page
			if (onFragmentClickListener != null) {
				onFragmentClickListener.onSwitchFragment(
						A03_NewAccount.A03_FRAGMENT_CODE, null);
			}
			break;
		case R.id.a02_bt_password:
			// next page
			if (onFragmentClickListener != null) {
				onFragmentClickListener.onSwitchFragment(
						A05_Pass.A05_FRAGMENT_CODE, null);
			}
			break;
		default:
			break;
		}

	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		try {
			onFragmentClickListener = (OnFragmentClickListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString()
					+ " must implement OnFragmentClickListener");
		}
	}
}
